# 继承Thread类实现多线程
import threading
import time

num = 0

# 创建互斥锁对象
lock = threading.Lock()

def set_num1():
    global num

    for i in range(100000):
        # 互斥锁开启
        lock.acquire()
        num += 1
        # 互斥所关闭
        lock.release()

    print("set_num-----------" + str(num))


def set_num2():
    global num

    for i in range(100000):
        # 互斥锁开启
        lock.acquire()
        num += 1
        # 互斥所关闭
        lock.release()

    print("get_num-----------" + str(num))


if __name__ == "__main__":
    t1 = threading.Thread(target=set_num1)
    t2 = threading.Thread(target=set_num2)
    t1.start()
    t2.start()

    time.sleep(1)
    print("__main__-----------" + str(num))
